@extends('layouts.app')
@section('title', config('const.ab.ORDER_LIST'))

@section('content')
        <div class="col-lg-10 col-lg-offset-1">
            <div class="panel panel-default">
                <div class="panel-heading">
                    {{config('const.ab.ORDER_LIST')}}
                </div>
                <div class="panel-body">
                    <table class="table table-bordered order">
                        <thead>
                        <tr class="active">
                            <td colspan="6">
                                <div class="col-sm-12 text-right small">{{config('const.ab.CREATED_AT')}}：{{$order->created_at->format('Y-m-d H:i')}}</div>
                            </td>
                        </tr>
                        <tr>
                            <th class="col-sm-3">{{config('const.ab.GOODS')}}</th>
                            <th class="col-sm-2">{{config('const.ab.PRICE')}}</th>
                            <th class="col-sm-1">{{config('const.ab.AMOUNT')}}</th>
                            <th class="col-sm-2">{{config('const.ab.SUBTOTAL')}}</th>
                        </tr>
                        </thead>
                        @foreach($order->items as $item)
                            <tr>
                                <td class="product-info">
                                    <div>
                                        <a href="{{route('products.show', $item->product)}}">
                                            <img src="{{$item->product->image}}">
                                        </a>
                                    </div>
                                    <div>
                                <span class="product-title">
                                    <a href="{{route('products.show', $item->product)}}">
                                        {{$item->product->title}}
                                    </a>
                                </span>
                                        <span class="sku-title small">{{$item->productSku->title}}</span>
                                    </div>
                                </td>
                                <td>
                                    <em class="small">￥</em>{{$item->productSku->price}}
                                </td>
                                <td>
                                    {{$item->amount}}
                                </td>
                                <td>
                                    <em class="small">￥</em>{{$item->productSku->price* $item->amount}}
                                </td>
                            </tr>
                        @endforeach
                    </table>

                    <div class="order-msg">
                        <div>
                            <span>{{config('const.ab.CONSIGNEE_INFO')}}：</span>
                            <span>{{join(', ', $order->address)}}</span>
                        </div>
                        <div>
                            <span>{{config('const.ab.REMARK')}}：</span>
                            <span>{{$order->remark?: '-'}}</span>
                        </div>
                        <div>
                            <span>{{config('const.ab.SERIAL_NUMBER')}}：</span>
                            <span>{{$order->no}}</span>
                        </div>
                        <div>
                            <span class="text-right">{{config('const.ab.TOTAL_PRICE')}}：</span>
                            <span class="text-center h2 total_amount"><em class="small">￥</em>{{$order->total_amount}}</span>
                        </div>
                        <div>
                            <span class="text-right">{{config('const.ab.STATUS')}}：</span>
                            <span class="text-center">
                                @if($order->paid_at)
                                    @if($order->refund_status == 'REFUND_STATUS_PENDING')
                                        {{config('const.ab.PAID')}}
                                    @else
                                        {{config('const.ab.'.$order->refund_status)}}
                                    @endif
                                @elseif($order->closed)
                                    {{config('const.at.CLOSED')}}
                                @else
                                    {{config('const.ab.UNPAID')}}
                                @endif
                            </span>
                        </div>
                        @unless($order->paid_at)
                            <div>
                                <span>{{config('const.ab.CHOOSE_PAYMENT_MODE')}}　</span>
                                <span class="payment">
                                    <a href="{{route('payment.alipay', $order)}}">
                                        <svg class="icon zhifubao" aria-hidden="true">
                                            <use xlink:href="#icon-zhifupingtai-zhifubao"></use>
                                        </svg>
                                    </a>
                                </span>
                                <span class="payment">
                                    <a href="{{route('payment.wechat', $order)}}" id="wechat_pay">
                                        <svg class="icon weixin" aria-hidden="true">
                                            <use xlink:href="#icon-weixin"></use>
                                        </svg>
                                    </a>
                                </span>
                            </div>
                        @endunless
                    </div>
                </div>
            </div>
        </div>
@endsection

@push('body')
    <script>
        $(function(){
            $('#wechat_pay').click(function(){
                swal({
                    {{--content: $("<img src='{{route('payment.wechat', $order)}}' style='width:100%'>").get(0)--}}
                    content: $("{{route('payment.wechat', $order)}}").get(0)
                })
                return false;
            })
        })
    </script>
@endpush